import {Component, Input, OnInit} from '@angular/core';
import {ButtonSizeType} from '../../enums';
import {DhlCommonComponent} from '../../dhlCommonComponent';


/**
 * name: 按钮名字
 * type: {
 *     primary，
 *     default，
 *     danger，
 *     link
 * }
 */
@Component({
  selector: 'dhl-drop-down',
  templateUrl: './dhl-drop-down.component.html'
})
export class DhlDropDownComponent extends DhlCommonComponent implements OnInit {

  defaultClass = `${ButtonSizeType.DEFAULT}-button`;
  buttonClass = this.defaultClass;
  isLoading = false;

  @Input() name = 'button';
  @Input() type = 'primary';
  @Input() buttons = [];
  @Input() clickParams = {};

  @Input() set loading(value) {
    this.isLoading = value;
  };

  ngOnInit() {

  }

  @Input()
  set sizeType(value) {
    this.buttonClass = this.buttonClass.replace(this.defaultClass, '') + ` ${value}-button`;

  }

  get sizeType() {
    return this.buttonClass;
  }

  finish() {
    this.isLoading = false;
  }

  btnClick(obj) {
    if (obj.click) {
      obj.click({...this.clickParams, finished: this.finish()});
    }
  }
}
